package com.zhou.service.impl.event;

import com.zhou.enums.WxMessageType;
import com.zhou.service.WxEventStrategy;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author lcz
 * @desc 消息策略
 * @mail lcz_0130@163.com
 * @date 2023/12/28
 */

@Service("text")
@Slf4j
public class TextStrategy implements WxEventStrategy {


    @Resource
    private WxMpService wxMpService;

    @Override
    public void execute(Map<String, String> requestMap, HttpServletResponse response) throws Exception {
        // 发送方账号
        String openId = requestMap.get("FromUserName");
        String acceptContent = requestMap.get("Content");
        // 1.获取用户输入的内容
        log.info("用户输入：{}", acceptContent);
        // 关闭输出流，避免微信服务端重复发送信息
        WxMpKefuMessage wxMpKefuMessage = new WxMpKefuMessage();
        wxMpKefuMessage.setToUser(openId);
        wxMpKefuMessage.setMsgType(WxMessageType.TEXT.getType());
        // 2.根据用户输入的内容，返回对应的内容
        wxMpKefuMessage.setContent("功能开发中，敬请期待！");
        log.info("回复消息 : {}", wxMpKefuMessage.getContent());
        // 3.返回的内容，发送给用户
        wxMpService.getKefuService().sendKefuMessage(wxMpKefuMessage);
    }


}
